<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>后台管理--菜单列表</title>
    <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet"/>
    <link href="${ctxStatic}/ligeruilib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css">
    <link href="${ctxStatic}/css/kpiui.css" rel="stylesheet"/>
    <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
    <script src="${ctxStatic}/layui/layui.all.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
    <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>
    <link href="${ctxStatic}/css/kpiuitanchu.css" rel="stylesheet"/>


    <style>
        .pdf > table {
            width: 100%;
            font-size: .938em;
            border-collapse: collapse; /*边框会合并为一个单一的边框*/
        }

        .pdf th {
            text-align: left;
            padding: .5em .5em;
            font-weight: bold;
            background: #66677c;
            color: #fff;
        }

        .pdf td {
            padding: .5em .5em;
            border-bottom: solid 1px #ccc;
        }

        .pdf table, .pdf table tr th, .pdf table tr td {
            border: 1px solid #0094ff;
        }

        /*设置边框的*/
    </style>

</head>
<body>


<div class="tanchucontent" style="margin:10px">

    <div class="layui-form">
        <table>
            <tr>
                <td class="td_right">人员：</td>
                <td colspan="3">
                    <!--  <select name="userid" lay-verify="required" >
                <c:forEach var="item" items="${userlst}">
                  <option value="${item.userid}">${item.realname} (${item.orgname})</option>
                </c:forEach>
         </select>-->

                    <input type="text" id="userid" autocomplete="off" lay-verify="ruserid" style="padding-left:10px;"
                           class="layui-input">

                </td>
            </tr>

            <tr>
                <td class="td_right">评分人：</td>
                <td colspan="3">
                    <!--  <select name="Leader" lay-verify="required">
               <c:forEach var="item" items="${userlst}">
                  <option value="${item.userid}">${item.realname} (${item.orgname})</option>
                </c:forEach>
         </select>-->
                    <input type="text" id="Leader" lay-verify="ruserid" class="layui-input">

                </td>
            </tr>


            <tr>
                <td style="text-align: center;height:50px" colspan="4">
                    <button class="button" onclick="save()" lay-filter="demo1" id="btnsave">保存</button>

                </td>
            </tr>
        </table>

    </div>

    <input type="hidden" id="hidUserId" value="">
    <input type="hidden" id="hidAudioId" value="">
    <div class="content" style="margin-left: 20px">

        <table class="layui-table " lay-data="" lay-filter="attbmhzlist" id="attbmhzlist"></table>
        <script type="text/html" id="operate">
            <img class="btn-img" src="${ctxStatic}/images/index/btn_delete.png" lay-event="del" alt="删除" title="删除">
        </script>
    </div>


</div>
</div>


</div>
</body>
<script>
    var _table;
    var _form;
    var ids = [];
    $(function () {

        initForm();

        _form.render('select');

        initTable();
        loadUser();
        $(document).on("click", ".layui-table-main tr", function () {

            for (var i = 0; i < ids.length; i++) {

                if (ids[i].index == $($(this)).data('index')) {

                    var userId = ids[i].value;
                    var audioId = ids[i].audioId;
                    $("#userid").ligerGetComboBoxManager().selectValue(userId);
                    $("#Leader").ligerGetComboBoxManager().selectValue(audioId);

                    $('#hidUserId').val(userId);
                    $('#hidAudioId').val(audioId);
                }


            }

            ;

        });

    })


    function save() {
        var userData = $("#userid").ligerGetComboBoxManager().getSelected();
        var audioData = $("#Leader").ligerGetComboBoxManager().getSelected()
        var _userId;
        var _audioId;
        if (!userData || !audioData) {

            if ($('#hidUserId').val() == '' || $('#hidAudioId').val() == '') {
                layer.msg('请选择完整的信息', {icon: 0})
                return;
            } else {

                _userId = $('#hidUserId').val();
                _audioId = $('#hidAudioId').val();
            }


        } else {
            _userId = userData.userid;
            _audioId = audioData.userid;
        }


        $.ajax({
            type: "POST",
            url: "addUserAduio",
            data: {userId: _userId, audioId: _audioId},
            beforeSend: function (XHR) {

            },
            success: function (data) {
                if (data > 0) {
                    search();
                    layer.msg('保存成功', {icon: 1})

                } else {
                    layer.msg('保存失败', {icon: 0})
                }
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });
    }


    function deleteentity(listid) {
        $.ajax({
            type: "POST",
            url: "deleteUserAduio",
            data: {listid: listid},
            beforeSend: function (XHR) {

            },
            success: function (data) {
                if (data > 0) {
                    search();
                    layer.msg('删除成功', {icon: 1})

                } else {
                    layer.msg('删除失败', {icon: 0})
                }
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });
    }

    function loadUser() {
        $("#userid").ligerComboBox(
            {
                url: '../common/get_audiouser_list',
                valueField: 'userid',
                textField: 'realname',
                selectBoxWidth: 441,
                autocomplete: true,
                keySupport: true,
                valueFieldID: "hid",
                onSelected: function (userid, realname) {//id为空值，name为选择的值


                },
                renderItem: function (e) {
                    var data = e.data, key = e.key;
                    var out = [];
                    out.push('<div>' + data.realname + '</div>');
                    out.push('<div class="desc">实际工作单位：' + data.orgname + '<font style="margin-left:20px">人事关系所在单位：' + data.rsgxorgname + '</font></div>');
                    return out.join('');
                },
                onSuccess: function (data) {
                    if ($("#hidedituserid").val() > 0) {
                        $("#userid").ligerGetComboBoxManager().selectValue($("#hiduserid").val());
                    }

                },
                width: 443
            }
        );

        $("#Leader").ligerComboBox(
            {
                url: '../common/get_Leader_list',
                valueField: 'userid',
                textField: 'realname',
                selectBoxWidth: 441,
                autocomplete: true,
                keySupport: true,
                valueFieldID: "hid",
                onSelected: function (userid, realname) {//id为空值，name为选择的值


                },
                renderItem: function (e) {
                    var data = e.data, key = e.key;
                    var out = [];
                    out.push('<div>' + data.realname + '</div>');
                    out.push('<div class="desc">实际工作单位：' + data.orgname + '<font style="margin-left:20px">人事关系所在单位：' + data.rsgxorgname + '</font></div>');
                    return out.join('');
                },
                onSuccess: function (data) {


                },
                width: 443
            }
        );

    }


    function initForm() {
        layui.use('form', function () {
            form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功


            form.render();
            _form = form;
        });
    }

    function initTable() {

        layui.use('table', function () {
            table = layui.table;
            table.init('attbmhzlist', {
                height: $(window).height() - 100
                , url: 'getUserAduio' // 数据接口
                // , page: true // 开启分页
                // , limit: 40
                , id: 'attbmhzlist'
                // , limits: [20, 40, 80, 100]
                , method: "post"
                , cols: [[ // 表头
                    {type: 'numbers'},
                    //{field : 'rowNum',title : '序号',width : 70,align : 'center'}
                    {field: 'userName', title: '姓名', align: 'center'}
                    , {field: 'orgname', title: '单位', align: 'center'}
                    , {field: 'cardNo', title: '身份证号', align: 'center'}
                    , {field: 'ldzw', title: '单位', align: 'center'}
                    , {field: 'audioName', title: '审核人', align: 'center'}
                    , {title : '操作',width : 100,align : 'center',toolbar : '#operate'}
                ]]
                , request: {
                    type: 'post'
                }
                , where: {
                    where: ''
                }
                , done: function (res, page, count) {
                    var $rows = $('.layui-table-main tr');
                    for (var i = 0; i < $rows.length; i++) {
                        $($rows[i]).data('userid', res.data[i].userId)

                    }
                    ids = [];

                    for (var i = 0; i < res.data.length; i++) {
                        ids.push({index: i, value: res.data[i].userid, audioId: res.data[i].audioId});


                    }
                }


            });
            //监听工具条
            table.on('tool(attbmhzlist)', function(obj){
                var data = obj.data;
                if(obj.event === 'del'){
                    top.mylayui.confirm('确定要删除吗？',{icon: 0}, function(index,dd){
                        top.mylayui.close(index);
                        console.log("deleteTest");
                        deleteentity(data.id);
                    });
                } else if(obj.event === 'edit'){
                    //layer.alert('编辑行：<br>'+ JSON.stringify(data))
                }
            });

            _table = table;
        })
    }

    function search() {

        _table.reload('attbmhzlist', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,
            where: {
                where: ''
            }
        })
    }

</script>
</html>
